package com.sky.controller.admin;

import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.pojo.Employee;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.EmployService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin/employee")
public class EmployController {

    @Autowired
    private EmployService employService;

    @PostMapping()
    public Result add(@RequestBody EmployeeDTO employeeDTO){
        employService.add(employeeDTO);
        return Result.success();
    }

    @GetMapping("/page")
    public Result findByPage(EmployeePageQueryDTO employeePageQueryDTO){
        PageResult byPage = employService.findByPage(employeePageQueryDTO);
        return Result.success(byPage);
    }
    @PostMapping("/status/{status}")
    public Result authority(@PathVariable Integer status,Integer id){
        employService.authority(status,id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        Employee byId = employService.findById(id);
        return Result.success(byId);
    }

    @PutMapping()
    public Result update(@RequestBody Employee employee){
        employService.update(employee);
        return Result.success();
    }
}
